package cn.javastudy.jdbc.base;

import static cn.javastudy.jdbc.GlobalProperties.password;
import static cn.javastudy.jdbc.GlobalProperties.url;
import static cn.javastudy.jdbc.GlobalProperties.user;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 快速入门
 */
public class QuickStarter {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // 注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        try(
            // 获取连接对象
            Connection connection = DriverManager.getConnection(url, user, password);
            // 执行SQL并获取结果集
            ResultSet resultSet = connection.prepareStatement("SELECT * FROM t_emp").executeQuery();
        ) {
            // 打印结果
            while (resultSet.next()) {
                System.out.print(resultSet.getString(1) + " ");
                System.out.print(resultSet.getString(2) + " ");
                System.out.println(resultSet.getString(3));
            }
        }
    }
}
